package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.icid.store.business.delegate.ImageDelegate;
	import com.icid.store.event.GetImageListEvent;
	import com.icid.store.event.SetImageInfoEvent;
	import com.icid.store.model.ImageModelLocator;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;

	public class SetImageInfoCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:ImageDelegate;
		private var setImageInfoEvent:SetImageInfoEvent;
		private var imageModel:ImageModelLocator = ImageModelLocator.getInstance();
		public function SetImageInfoCommand()
		{
			super();
			delegate = new ImageDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			setImageInfoEvent = SetImageInfoEvent(event);
			delegate.create(setImageInfoEvent.simpleImage);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			switch(data.result.info)
			{
				case "success":
					Alert.show("Upload product image success!","SUCCESS");
					CairngormEventDispatcher.getInstance().dispatchEvent(new GetImageListEvent());
					break;
				case "failure":
					Alert.show("Upload product image failure!","FAILURE");
					break;
				default:
					break;		
			}
		}
		
	}
}